<template>
  <s-modal
    title="修改"
    :visible="visible"
    width="800px"
    ok-text="保存"
    :confirm-loading="confirmLoading"
    :closable="!confirmLoading"
    @ok="save()"
    @cancel="()=>{if(!confirmLoading){ visible=false }}"
  >
    <div style="height:400px">
      <s-scroll>
        <s-form ref="form" :value="formValue">
          <s-form-item
            label="任务名称"
            size="middle"
            name="taskName"
            :colon="true"
            :display-title="true"
            :rules="[{'max':255,'message':'最长为255位'}]"
          >
            <s-input
              :allow-clear="true"
              placeholder="请输入任务名称"
              v-model="formValue.taskName"
              />
          </s-form-item>
          <s-form-item
            label="任务详情"
            size="middle"
            name="taskContent"
            :colon="true"
            :display-title="true"
            :rules="[{'max':255,'message':'最长为255位'}]"
          >
            <s-input
              :allow-clear="true"
              placeholder="请输入任务详情"
              v-model="formValue.taskContent"
              />
          </s-form-item>
          <s-form-item
            label="执行时间"
            size="middle"
            name="createTime"
            :colon="true"
            :display-title="true"
          >
            <s-date-picker
              :allow-clear="true"
              placeholder="请输入提交时间"
              type="date"
              value-format="YYYY-MM-DD"
              :show-time="true"
              v-model="formValue.createTime"
              />
          </s-form-item>
          <s-form-item
            label="协同人"
            size="middle"
            name="associate"
            :colon="true"
            :display-title="true"
            :rules="[{'max':255,'message':'最长为255位'}]"
          >
            <s-input
              :allow-clear="true"
              placeholder="请输入协同人"
              v-model="formValue.associate"
              />
          </s-form-item>

        </s-form>
      </s-scroll>
    </div>
  </s-modal>
</template>

<script>

export default {
  name: 'Update',
  emits: ['change'],
  data() {
    return {
      formValue: {},
      confirmLoading: false,
      visible: false
    }
  },
  methods: {
    open(id) {
      this.formValue = {}
      this.$loading(true)
      this.$api.GET('/modules/doorCalendarTasks/selectOneById', { id: id }).then(res => {
        if (!res.data) {
          this.$loading(false)
          this.visible = false
          this.$message.warn('数据不存在')
        } else {
          this.formValue = res.data
          this.$loading(false)
          this.visible = true
        }
      }).catch(() => {
        this.$loading(false)
      })
    },
    save() {
	  const _this=this
      const form = this.$refs.form
      form.validate((values,fullValue) => {
	    
        this.confirmLoading = true
        values.id = this.formValue.id
        this.$api.PUT('/modules/doorCalendarTasks/update', values).then(res => {
          this.confirmLoading = false
          this.visible = false
          this.$emit('success');
          this.$message.info(res.msg)
        }).catch(() => {
          this.confirmLoading = false
        })
      })
    }
  }
}
</script>

<style lang="less" scoped>

</style>